package com.iwdm.renovation.ui.home;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.R;
import com.iwdm.renovation.databinding.FragmentHomeItemBinding;
import com.iwdm.renovation.ui.home.details.HomeActivity;

public class MyhomeRecyclerViewAdapter extends RecyclerView.Adapter<MyhomeRecyclerViewAdapter.ViewHolder> {

    FragmentHomeItemBinding binding;
    public MyhomeRecyclerViewAdapter() {

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        binding  = FragmentHomeItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        holder.mContentView.setText(position%2==0?"什么是现代简约风格.....":"我的小家装修攻略");
        holder.imgdianzan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.isdianzan =  !holder.isdianzan;
                holder.imgdianzan.setImageResource( holder.isdianzan?R.drawable.dianzan:R.drawable.dianzan_1);
            }
        });
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.getContext().startActivity(new Intent(v.getContext(), HomeActivity.class).putExtra("position",position%2));
            }
        });
    }

    @Override
    public int getItemCount() {
        return 30;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public boolean isdianzan = true;
        public final View mView;
        public final TextView mContentView;
        public final ImageView imgdianzan;

        public ViewHolder(FragmentHomeItemBinding binding) {
            super(binding.getRoot());
            mView = binding.getRoot();
            mContentView = binding.content;
            imgdianzan = binding.imgdianzan;
        }
    }
}
